/*++
"This software program is available to you under a choice of one of two 
licenses.  You may choose to be licensed under either the GNU General Public 
License (GPL) Version 2, June 1991, available at 
http://www.fsf.org/copyleft/gpl.html, or the BSD License, the text of
which follows:

Copyright (c) 1996-2005, Intel Corporation. All rights reserved.

Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this 
list of conditions and the following disclaimer. 

Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or 
other materials provided with the distribution. 

Neither the name of the Intel Corporation ("Intel") nor the names of its 
contributors may be used to endorse or promote products derived from this
software without specific prior written permission. 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
--*/
#ifndef __XLLP_TAVOR_MICCO_AUDIO_H__
#define __XLLP_TAVOR_MICCO_AUDIO_H__

#include "xllp_gpio.h"
#include "xllp_mfp.h"
#include "xllp_i2c.h"
#include "xllp_defs.h"
#include "xllp_acodec.h"

//**************************************************************************
// CODEC XLLP Common Definition 
//**************************************************************************
#define	CODEC_GAIN_MIN		0
#define	CODEC_GAIN_MAX		63
#define	CODEC_GAIN_RANGE	64	
#define	CODEC_VALID_GAIN(A)	(A>=CODEC_GAIN_MIN && A<=CODEC_GAIN_MAX)
#define   CODEC_REG_NUM              0x15

//**************************************************************************
// Micco Audio Register Definition
//**************************************************************************

//**************************************************************************
// CODEC Input & Output Port Definition 
//**************************************************************************
#define	MICCO_CODEC_INPUT_NUMBER		7
enum MiccoInput{
	CODEC_AUX1 = 0,
	CODEC_AUX2,
	CODEC_AUX3,
	CODEC_MIC1,
	CODEC_MIC2,
	CODEC_PCM,
	CODEC_HIFI,
};

#define	MICCO_CODEC_OUTPUT_NUMBER	5
enum MiccoOutput{
	CODEC_BEAR = 0,
	CODEC_MONO,
	CODEC_STEREO,
	CODEC_LINE_OUT,
	CODEC_ADC,
};

enum MiccoCodecDigitalPort{
	MICCO_VOICE = 0,
	MICCO_HIFI,
};

struct	MiccoObject{
	XLLP_UINT32_T	I2CBase;
	XLLP_UINT32_T	OSTBase;
	XLLP_UINT32_T	MFPBase;
	XLLP_UINT32_T	SSPBase;
	XLLP_UINT32_T	I2SBase;
	
	// A buffer to save CODEC register for fast access
	unsigned char	Reg[18];

	// Sample rate setting
	XLLP_UINT32_T	PlaySampleRate;
};


//**************************************************************************
// Micco Input & Output Operations 
//**************************************************************************
// Enable a CODEC output port. Return 0 if port is enabled successfully 
// and non-zero if port cannot be enalbed. After a output port is enabled,
// it's unmuted and ready to play sound. Port gain won't be impacted by
// this function.
XLLP_ACODEC_ERROR_T MiccoCodecEnableOutput(enum MiccoOutput);
// Disable a CODEC output port. Return 0 if port is disabled successfully
// and non-zero if port cannot be disabled. A disabled port is a mute port.
// This function won't impact port gain.
XLLP_ACODEC_ERROR_T MiccoCodecDisableOutput(enum MiccoOutput);

// Set the gain of a CODEC output port
// Argument
//	enum	MiccoOutput	Port
//		Target output port
//	int	Gain
//		Output gain to be set. Must between CODEC_GAIN_MIN
//		and CODEC_GAIN_MAX.
// Return 0 if operation succeeds and non-zero if operation fails
XLLP_ACODEC_ERROR_T MiccoCodecSetOutputVolume(enum MiccoOutput Port, int Gain);

// Enable a CODEC input port. Return 0 if port is enabled successfully 
// and non-zero if port cannot be enalbed. After a input port is enabled,
// it's unmuted and ready to receive sound. Port gain won't be impacted by
// this function.
XLLP_ACODEC_ERROR_T MiccoCodecEnableInput(enum MiccoInput);
// Disable a CODEC input port. Return 0 if port is disabled successfully
// and non-zero if port cannot be disabled. A disabled port is a mute port.
// This function won't impact port gain.
XLLP_ACODEC_ERROR_T      MiccoCodecDisableInput(enum MiccoInput);

// Set the gain of a CODEC input port
// Argument
//	enum	MiccoInput	Port
//		Target input port
//	int	Gain
//		Output gain to be set. Must between CODEC_GAIN_MIN
//		and CODEC_GAIN_MAX.
// Return 0 if operation succeeds and non-zero if operation fails
XLLP_ACODEC_ERROR_T MiccoCodecSetInputVolume(enum MiccoInput, int);

// Set CODEC digital port sample rate. Return 0 if operation succeeds and
// non-zero if operation fails. Argument SampleRate is the target sample rate.
// Please refer to CODEC document for available sample rate. SampleRate is
// an integer in HZ. For example, it's 11025 if sample rate is 11.025K and
// it's 44100 if sample rate is 44.1K. Input and output sample rate must be
// same of PCM port.
XLLP_ACODEC_ERROR_T MiccoCodecSetSampleRate(enum MiccoCodecDigitalPort, int);

// Initialize CODEC. This function must be called before other CODEC function
// is called to reset CODEC to a known state. This function will disconnect
// all connection between input and output port, disable all input and output
// port, set all amplifier to lowest gain and set digital port sample rate to 
// lowest sample rate. Caller must prepare a buffer to save CODEC object. 
// Caller should not touch data in the CODEC object later. However, it must
// past this CODEC object to XLLP when it call CODEC XLLP later.
XLLP_ACODEC_ERROR_T MiccoCodecInit(void);

#endif //__XLLP_TAVOR_MICCO_AUDIO_H__


